home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
presto
/
presto10.lha
/
src
/
spinlock.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-11
|
2KB
|
112 lines
//
// spinlock.c
// non-inlined functions for spinlocks
//
// Modification History:
//
// 28-Dec-1989 JEF
// Add class HC_Spinlock (for sequent symmetry only). This variation of
// a spinlock works well when there is high contention for the lock.
// After original by raj.
//
#include <stream.h>
#include "presto.h"
void
Spinlock::print(ostream& s)
{
s << form("(Spinlock)this=0x%x, sl_lock=0x%x", this, this->sl_lock);
}
#ifdef mips
extern "C" int atomic_test_and_set(slock_t *);
void
s_init_lock(slock_t* l)
{
*l = 0;
}
void
s_lock(slock_t *l)
{
while (atomic_test_and_set (l))
;
}
void
s_unlock(slock_t* l)
{
*l = 0;
}
int
s_clock(slock_t* l)
{
return((*l) ? 0 : (*l)++);
}
#endif /* mips */
#ifdef sun
#ifdef DO_SPINLOCK_INLINE
//
// s_lock, s_unlock and s_clock are defined in sun_lock.s
//
void s_init_lock(slock_t* l) {
*l = 0;
}
void s_lock(slock_t *l) {
while (*l) ; *l = 1;
}
void s_unlock(slock_t* l) {
*l = 0;
}
int s_clock(slock_t* l) {
return((*l) ? 0 : (*l)++);
}
#else
void Spinlock::~Spinlock() {
if (sl_lock)
unlock();
}
void Spinlock::unlock() {
(void) S_UNLOCK(&sl_lock);
# ifndef NO_PREEMPT
thisthread->releasingspinlock();
# endif NO_PREEMPT
}
void Spinlock::lock() {
# ifndef NO_PREEMPT
thisthread->holdingspinlock();
# endif NO_PREEMPT
(void) S_LOCK(&sl_lock);
}
#endif /* DO_SPINLOCK_INLINE */
#endif /* sun */
//
// non-inlined functions for HC_Spinlocks
//
#ifdef sequent
#ifdef i386
void
HC_Spinlock::print(ostream& s)
{
// XXX note: understands what a hc_slock_t looks like...
s << form("(HC_Spinlock)this=0x%x, sl_lock=0x%x", this, sl_lock.x[0][0]);
s << "\n";
}
#endif /* i386 */
#endif /* sequent */